package sd.czw.com.mmgapp.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import sd.czw.com.mmgapp.R;
import sd.czw.com.mmgapp.activity.RzActivity;
import sd.czw.com.mmgapp.model.shouyebean.HomeInfo;

/**
 * Created by czw
 * desc 描述：
 * on 2017/7/6.
 */
public class RuzhuRvAdapter extends RecyclerView.Adapter<RuzhuRvAdapter.MyViewHolder> {

    private Context context;
    private List<HomeInfo.ErrmsgBean.CatImgBean> datas;
    private List<String> path = new ArrayList<>();

    public RuzhuRvAdapter(Context context, List<HomeInfo.ErrmsgBean.CatImgBean> datas) {
        this.context = context;
        this.datas = datas;
        initpath();
    }

    private void initpath() {
        path.add("http://miemiegou.com/wap/themes/miqinew/images/yimage/top01.jpg");
        path.add("http://miemiegou.com/wap/themes/miqinew/images/yimage/top02.jpg");
        path.add("http://miemiegou.com/wap/themes/miqinew/images/yimage/top03.jpg");
        path.add("http://miemiegou.com/wap/themes/miqinew/images/yimage/top04.jpg");
        path.add("http://miemiegou.com/wap/themes/miqinew/images/yimage/top05.jpg");
        path.add("http://miemiegou.com/wap/themes/miqinew/images/yimage/top06.jpg");
        path.add("http://miemiegou.com/wap/themes/miqinew/images/yimage/top07.jpg");
        path.add("http://miemiegou.com/wap/themes/miqinew/images/yimage/new_banner.jpg");
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.rzrv_child, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        if (datas != null){
            holder.layoutHomeTvtvname.setText(datas.get(position).getName());
            holder.layoutHomeTvtvintro.setText(datas.get(position).getIntro());
            Glide.with(context).load(datas.get(position).getUrl()).placeholder(new ColorDrawable(Color.parseColor("#f5f5f5"))).into(holder.layoutHomeGvimage);
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context, RzActivity.class);
                    intent.putExtra("goods_id",datas.get(position).getId()+"");
                    intent.putExtra("titles",datas.get(position).getName());
                    intent.putExtra("path",datas.get(position).getImg());

                    context.startActivity(intent);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.layout_home_tvtvname)
        TextView layoutHomeTvtvname;
        @Bind(R.id.layout_home_tvtvintro)
        TextView layoutHomeTvtvintro;
        @Bind(R.id.layout_home_gvimage)
        ImageView layoutHomeGvimage;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
